﻿namespace LearnDSSortings;

public class BubbleSort
{
    public void Sort(int[] arr)
    {
        int n = arr.Length;
        for (int pass = n - 1; pass >= 0; pass--)
        {
            for (int i = 0; i < pass; i++)
            {
                if (arr[i] > arr[i + 1])
                {
                    Swap(arr, i, i + 1);
                }
            }
        }
    }

    private void Swap(int[] arr, int i, int j)
    {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}